<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>图片轮播</title>
    <style>
        #lunbo {
            width: 1226px;
            height: 460px;
            position: relative;
            margin: 0 auto;
        }
        #lunbo img {
            width: 520px;
            height: 520px;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }
    </style>
</head>
<body>
<div id="lunbo">
    <img src="img/lunbo1.png">
    <img src="img/lunbo2.png">
    <img src="img/lunbo3.png">
    <img src="img/lunbo4.png">
    <img src="img/lunbo5.png">
    <img src="img/lunbo6.png">
</div>
<script>
    let imgArr = document.getElementById('lunbo').getElementsByTagName('img');
    //图片数量
    let imgNum = imgArr.length
    //用此索引来跟踪图片轮播顺序（第一张图片索引即为0）
    let index = 0;
    //初始化第一张图片
    imgArr[0].style.display = 'block';
    //每隔3秒轮播一张图片
    setInterval(function(){
        index++;
        //如果轮播到最后一张图片，那么索引就归零
        if (index > imgNum - 1) {
            index = 0;
        }
        //先隐藏所有图片
        for (let i=0;i<imgNum; i++) {
            imgArr[i].style.display = 'none';
        }
        //再显示当前图片
        imgArr[index].style.display = 'block';
    }, 3000);
</script>
</body>
</html>